Add core support for track segement. Read and write in GPX.
authorrobertl <robertl>
Wed, 14 Apr 2010 01:10:44 +0000 (01:10 +0000)
committerrobertl <robertl>
Wed, 14 Apr 2010 01:10:44 +0000 (01:10 +0000)
defs.h
gpx.c
route.c
tpo.c
xmldoc/chapters/build.xml
xmldoc/chapters/preface.xml
xmldoc/chapters/styles.xml

diff --git a/defs.h b/defs.h
index 24d39ce495fb7663bcf6f65b53784fbf8ef06f1a..8f24fc1425492a24db28067a8576502a3f8b1a00 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -355,6 +355,7 @@ typedef struct {
        ... and others
        */
        unsigned int is_split:1;                /* the waypoint represents a split */
+       unsigned int new_trkseg:1;              /* True if first in new trkseg. */
 
        
 } wp_flags;
diff --git a/gpx.c b/gpx.c
index 1be06754a11aeb63993b0a7bd0daf870e7ba0cee..2e0b675b96de0e1678cd4673b61a30ee101c8408 100644 (file)
--- a/gpx.c
+++ b/gpx.c
@@ -64,8 +64,10 @@ static char *suppresswhite = NULL;
 static char *urlbase = NULL;
 static route_head *trk_head;
 static route_head *rte_head;
+static const route_head *current_trk_head;             // Output.
 /* used for bounds calculation on output */
 static bounds all_bounds;
+static int next_trkpt_is_new_seg;
 
 static format_specific_data **fs_ptr;
 
@@ -692,6 +694,10 @@ gpx_start(void *data, const XML_Char *xml_el, const XML_Char **xml_attr)
                break;
        case tt_trk_trkseg_trkpt:
                tag_wpt(attr);
+               if (next_trkpt_is_new_seg) {
+                       wpt_tmp->wpt_flags.new_trkseg = 1;
+                       next_trkpt_is_new_seg = 0;
+               }
                break;
        case tt_unknown:
                start_something_else(el, attr);
@@ -1050,6 +1056,9 @@ gpx_end(void *data, const XML_Char *xml_el)
                break;
        case tt_trk:
                break;
+       case tt_trk_trkseg:
+               next_trkpt_is_new_seg = 1;
+               break;
        case tt_trk_trkseg_trkpt:
                track_add_wpt(trk_head, wpt_tmp);
                wpt_tmp = NULL;
@@ -1705,6 +1714,7 @@ static void
 gpx_track_hdr(const route_head *rte)
 {
        fs_xml *fs_gpx;
+       current_trk_head = rte;
 
        gbfprintf(ofd, "<trk>\n");
        write_optional_xml_entity(ofd, "  ", "name", rte->rte_name);
@@ -1720,13 +1730,21 @@ gpx_track_hdr(const route_head *rte)
                }
        }
 
-       gbfprintf(ofd, "<trkseg>\n");
 }
 
 static void
 gpx_track_disp(const waypoint *waypointp)
 {
        fs_xml *fs_gpx;
+       int first_in_trk;
+       first_in_trk = waypointp->Q.prev == &current_trk_head->waypoint_list;
+
+       if (waypointp->wpt_flags.new_trkseg) {
+               if (!first_in_trk) {
+                       gbfprintf(ofd, "</trkseg>\n");
+               }
+               gbfprintf(ofd, "<trkseg>\n");
+       }
 
        gbfprintf(ofd, "<trkpt lat=\"" FLT_FMT_T "\" lon=\"" FLT_FMT_T "\">\n",
                waypointp->latitude,
@@ -1766,8 +1784,11 @@ gpx_track_disp(const waypoint *waypointp)
 static void
 gpx_track_tlr(const route_head *rte)
 {
-       gbfprintf(ofd, "</trkseg>\n");
+       if (!QUEUE_EMPTY(&current_trk_head->waypoint_list)) {
+               gbfprintf(ofd, "</trkseg>\n");
+       }
        gbfprintf(ofd, "</trk>\n");
+       current_trk_head = NULL;
 }
 
 static
diff --git a/route.c b/route.c
index e6f8b1ff68b24a7cfada6d2a44436e3babf9bc60..bfd378d3e9ad90b0f0444c3315593846bddff3ec 100644 (file)
--- a/route.c
+++ b/route.c
@@ -189,6 +189,13 @@ route_add_wpt( route_head *rte, waypoint *wpt )
 void 
 track_add_wpt( route_head *rte, waypoint *wpt )
 {
+       // First point in a track is always a new segment.
+       // This improves compatibility when reading from 
+       // segment-unaware formats.
+       if (QUEUE_EMPTY(&rte->waypoint_list)) {
+               wpt->wpt_flags.new_trkseg = 1;
+       }
+       
        any_route_add_wpt( rte, wpt, &trk_waypts, 0 );
 }
 
@@ -209,6 +216,11 @@ route_find_waypt_by_name( route_head *rh, const char *name )
 static void 
 any_route_del_wpt( route_head *rte, waypoint *wpt, int *ct)
 {
+       if (wpt->wpt_flags.new_trkseg && wpt != (waypoint*)QUEUE_LAST(&rte->waypoint_list)) {
+               waypoint* wpt_next = (waypoint*)QUEUE_NEXT(&wpt->Q);
+               wpt_next->wpt_flags.new_trkseg = 1;
+       }
+       wpt->wpt_flags.new_trkseg = 0;
        dequeue( &wpt->Q );
        rte->rte_waypt_ct--;
        if ( ct ) (*ct)--;
@@ -236,7 +248,7 @@ route_disp (const route_head *rh, waypt_cb cb )
        QUEUE_FOR_EACH(&rh->waypoint_list, elem, tmp) {
                waypoint *waypointp;
                waypointp = (waypoint *) elem;
-                       (*cb)(waypointp);
+               (*cb)(waypointp);
        }
                
 }
diff --git a/tpo.c b/tpo.c
index 45a6491b2511fc4b34f5278108baa5ba6df6895d..253e681ecfac29b4ecfdb670e180a25f2cc52a20 100644 (file)
--- a/tpo.c
+++ b/tpo.c
@@ -670,7 +670,7 @@ void tpo_process_tracks(void)
                 llvalid = 1;
 
                 waypoint_temp = tpo_convert_ll(lat, lon);
-                route_add_wpt(track_temp, waypoint_temp);
+                track_add_wpt(track_temp, waypoint_temp);
                 waypoint_count++;
             }
 
index 66ec48090054d246d6dc3247bd196f9f788175c3..9bcb3584dfd0fea60d4303edd0677358e5c57d51 100644 (file)
@@ -1,5 +1,5 @@
 <chapter id="Getting_and_Building">
-  <title>Getting it or Building it</title>
+  <title>Getting or Building GPSBabel</title>
 <sect1 id="Download">
 <title>Downloading - the easy way.</title>
   <para> 
index e83e1560d441c04e49bf21647559e3c78291fe40..469cfbe8f7be807e565bc223d9ce46c5fa3564de 100644 (file)
@@ -1,5 +1,5 @@
    <preface id="Introduction">
-      <title>Introduction</title>
+      <title>Introduction to GPSBabel</title>
       <section id="The_Problem">
          <title>The Problem: Too many incompatible GPS file formats</title>
          <para> There are simply too many gratuitously different file formats
index 26f9c4937124f67bf89690415b54c8951177c071..49a0188ef96e64323ecff42823d89d03b665d526 100644 (file)
@@ -2,7 +2,7 @@
 <title>GPSBabel XCSV Style Files</title>
 
 <section id="styles_intro">
-<title>Introduction</title>
+<title>Introduction to GPSBabel Styles</title>
 <para>
 Often it is desirable to add a new file format for "one-off" work (perhaps
 you want to export something to a spreadsheet or graphing program) or to read